#include <gtest/gtest.h>
#include "core/acs_response.h"

using namespace aliyun;

class TestAcsResponse : public AcsResponse {
public:
  const string& GetInstanceId() {
    return instance_id_;
  }
protected:
  virtual const char* BaseKey(void) {
    return "TestAcsResponse";
  }
  virtual void UnmarshallerMap(std::map<string, string>& response_map) {
    UnmarshallerString(request_id_, response_map, "TestAcsResponse.RequestId");
    UnmarshallerString(instance_id_, response_map, "TestAcsResponse.InstanceId");
  }
private:
  string instance_id_;
};

TEST(core, AcsResponse) {
  TestAcsResponse test_acs_response;

  test_acs_response.SetCode("test.SetCode");
  ASSERT_STREQ("test.SetCode", test_acs_response.GetCode().c_str());

  test_acs_response.SetMessage("test.SetMessage");
  ASSERT_STREQ("test.SetMessage", test_acs_response.GetMessage().c_str());

  test_acs_response.SetRequestId("test.SetRequestId");
  ASSERT_STREQ("test.SetRequestId", test_acs_response.GetRequestId().c_str());

  test_acs_response.SetHostId("test.SetHostId");
  ASSERT_STREQ("test.SetHostId", test_acs_response.GetHostId().c_str());

  const char *json_body =
    "{"
    " \"RequestId\": \"04F0F334-1335-436C-A1D7-6C044FE73368\", "
    " \"InstanceId\": \"i-instance1\" "
    "}";
  test_acs_response.ParseBody((const unsigned char*)json_body, strlen(json_body), true, "JSON");
  ASSERT_STREQ("04F0F334-1335-436C-A1D7-6C044FE73368", test_acs_response.GetRequestId().c_str());
  ASSERT_STREQ("i-instance1", test_acs_response.GetInstanceId().c_str());

}

// end of file
